home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / music / patchlib.arc / PATCHSRC.ARC / PATCH.C < prev   
Text File  |  1985-11-20  |  44KB  |  1,676 lines

  1. #include    <curses.h>
  2.  
  3. /*
  4.  *    The following source code is being placed in the public domain
  5.  *    with the sole restriction that if any of it is used in any manner,
  6.  *    proper acknowledgement will be given to the original author -
  7.  *    Eric Pettersen
  8.  */
  9.  
  10. #define    Effect        (!((Random() >> 3) % weirdness))
  11. #define sfunc(i,b)    ((types[i][b] == 1) ? "high": ((types[i][b] == 2) ? \
  12.             " mid": " low"))
  13. #define Get_roll(a)    roll = get_roll(a)
  14. #define    AND_CHAR    241
  15. #define    OPTIONS        9
  16. #define    EDIT_OPTIONS    8
  17. #define    MAIN        0
  18. #define    EDIT        1
  19. #define    OK        0
  20. #undef    NULL
  21. #define    NULL        -1
  22. #define    ABORT        -2
  23. #define    BAD        -3
  24.  
  25. #define    VOICES        1000
  26.  
  27. /* either #define DX100 or CZ101 here */
  28. #ifdef    DX100
  29. #define    RANDOM_FILE    "DX100.DTA"
  30. #define    VOICE_FILE    "DXVOICES.DTA"
  31. #define    VOICE_SIZE    77
  32. #define    TOTAL_SIZE    93
  33. #else
  34. #define    RANDOM_FILE    "CZ101.DTA"
  35. #define    VOICE_FILE    "CZVOICES.DTA"
  36. #define    VOICE_SIZE    81
  37. #define    TOTAL_SIZE    128
  38. #define    VDT        0
  39. #define    VRm        1
  40. #define    VRl        2
  41. #define VD        3
  42. #define    SLOTS        4
  43.  
  44. char    table[SLOTS][100]; /* the CZMIDI.DTA data file fits in this table */
  45. int    dca_kf[10] = { 0, 8, 17, 26, 36, 47, 58, 69, 82, 95 };
  46. int    dcw_kf[10] = { 0, 31, 44, 57, 70, 83, 96, 110, 146, 255 };
  47. #endif
  48.  
  49. int    weirdness;
  50. int    ranges[VOICE_SIZE];        /* data from DX/CZDATA.DTA    */
  51. int    types[VOICE_SIZE][2];        /* is read into these        */
  52. int    tries[VOICE_SIZE][2];        /* arrays            */
  53. char    out[80], key_tbl[384];        /* data from KEYTAB.DTA goes in */
  54.                     /* key_tbl array        */
  55. int    cur_voice, load_ptr;        /* cur_voice: points to where    */
  56.                     /* next saved voice will go in    */
  57.                     /* the voices array (and also,    */
  58.                     /* therefore, how many voices    */
  59.                     /* we have in the library)    */
  60.                     /* load_ptr: which voice from    */
  61.                     /* voices array was last loaded    */
  62.                     /* into the synth        */
  63. long    cur_space;            /* how much free space on disk    */
  64. unsigned char    voices[VOICES][TOTAL_SIZE]; /* actual voices */
  65. char    v_names[VOICES+1][80];        /* associated voice names    */
  66.  
  67. /* main: Handle all main menu I/O and call any subroutines requested */
  68. main()
  69. {
  70.     char    key, ans;
  71.     char    voice[TOTAL_SIZE], v_name[80], search_str[80];
  72.     int    i, j, name_valid, load_voice, leng, found, init_rez;
  73.  
  74.     if ((init_rez = Getrez()) == 0) Setscreen(-1L, -1L, 1);
  75.     init_curses();
  76.     scr_func(CLEAR_SCR);
  77.     printf("Getting old voices from file\n\r");
  78.     get_voices(v_names, voices);
  79.     load_ptr = -1;
  80.     printf("Getting random voice weights from file\n\r");
  81.     initialize();
  82.     show_screen(MAIN);
  83.     do {
  84.         pos_cursor(8, 3+OPTIONS);
  85.         scr_func(ERASE_TO_EOP);
  86.         switch((int)(key = Crawcin())) {
  87.         case 'n':
  88.         case 'N':
  89.             printf("n");
  90.             printf("\n\rmaking voice");
  91.             make_voice(voice);
  92.             load_ptr = cur_voice;
  93.             /* FALL THROUGH */
  94.         case 'r':
  95.         case 'R':
  96.             if (key == 'r' || key == 'R'){
  97.                 printf("r");
  98.             }
  99.             if (load_ptr < 0)
  100.                 printf("\n\rno current voice\n\r");
  101.             else {
  102.                 printf("\n\rsending voice\n\r");
  103.                 if (load_ptr == cur_voice)
  104.                     send_voice(voice);
  105.                 else 
  106.                     send_voice(voices[load_ptr]);
  107.                 show_voice(load_ptr);
  108.             }
  109.             break;
  110.         case 's':
  111.         case 'S':
  112.             printf("s");
  113.             printf("\n\rreceiving voice\n\r");
  114. #ifndef    DEBUG
  115.             receive_voice(voice);
  116. #endif
  117.             do {
  118.                 do {
  119.                     pos_cursor(0,5+OPTIONS);
  120.                     scr_func(CLEAR_TO_EOL);
  121.                     printf("enter voice name: \007");
  122.                     printf("\n\r[ESC to abort]");
  123.                     pos_cursor(18, 5+OPTIONS);
  124.                     leng = get_str(v_name);
  125.                 } while (leng == 0);
  126.                 if (leng < 0) break;
  127.                 name_valid = TRUE;
  128.                 for(i=0; i<leng; i++)
  129.                     if (v_name[i]<32 || v_name[i]>127) {
  130.                         printf("\n\rName has invalid ");
  131.                         printf("character in it - ");
  132.                         printf("re-try");
  133.                         name_valid = FALSE;
  134.                         break;
  135.                     }
  136.                 v_name[i] = '\0';
  137.                 if (name_valid)
  138.                     for(i=0; i<cur_voice; i++) {
  139.                         if(!strcmp(v_names[i],v_name))
  140.                         {
  141.                             printf("\n\rThere is al");
  142.                             printf("ready a voice");
  143.                             printf(" named '%s'",
  144.                                 v_name);
  145.                             printf(" - re-try");
  146.                             name_valid = FALSE;
  147.                             break;
  148.                         }
  149.                     }
  150.             } while(name_valid == FALSE);
  151.             if (leng < 0) break;
  152. #ifdef    DX100
  153.             strncpy(voice+77, v_name, 10); 
  154.             for(i=strlen(v_name); i<10; i++) voice[77+i] = ' ';
  155. #endif
  156.             pos_cursor(0,6+OPTIONS);
  157.             scr_func(CLEAR_TO_EOL);
  158.             for(i=0; i<TOTAL_SIZE; i++) voices[cur_voice][i] = voice[i];
  159.             strcpy(v_names[cur_voice], v_name);
  160.             printf("writing voice '%s' to file\n\r", v_name);
  161.             write_voice(v_name, voice);
  162.             cur_voice++;
  163.             show_voice(load_ptr);
  164.             break;
  165.         case 'a':
  166.         case 'A':
  167.             printf("a");
  168.             goto test;
  169.         case 'l':
  170.         case 'L':
  171.             printf("l");
  172. test:
  173.             if (cur_voice == 0) {
  174.                 warn("No voices to load");
  175.                 break;
  176.             }
  177.             if (key == 'a' || key == 'A') {
  178.                 load_ptr = (load_ptr + 1) % cur_voice;
  179.                 goto load_it;
  180.             }
  181.             load_voice = get_v_num(5+OPTIONS);
  182.             if (load_voice == ABORT) break;
  183.             load_ptr = load_voice;
  184. load_it:
  185.             pos_cursor(0,6+OPTIONS);
  186.             scr_func(CLEAR_TO_EOL);
  187.             printf("Loading voice '%s'\n\r", v_names[load_ptr]);
  188.             send_voice(voices[load_ptr]);
  189.             show_voice(load_ptr);
  190.             break;
  191.         case 'w':
  192.         case 'W':
  193.             printf("w");
  194.             do {
  195.                 pos_cursor(0, 5+OPTIONS);
  196.                 scr_func(CLEAR_TO_EOL);
  197.                 printf("New weirdness factor: ");
  198.                 leng = get_num();
  199.                 if (leng == BAD || leng == 0) {
  200.                     printf("\n\rInput 1 or higher ");
  201.                     printf("[ESC to abort]");
  202.                 }
  203.             } while(leng == 0 || leng == BAD);
  204.             if (leng > 0) {
  205.                 weirdness = leng;
  206.                 show_weirdness();
  207.             }
  208.             break;
  209.         case 'e':
  210.         case 'E':
  211.             show_screen(EDIT);
  212.             edit();
  213.             show_screen(MAIN);
  214.             break;
  215.         case 'f':
  216.         case 'F':
  217.             printf("f");
  218.             Keytbl(key_tbl, key_tbl+128, key_tbl+256); 
  219.             pos_cursor(0, 5+OPTIONS);
  220.             printf("Enter string(s) to search for: \n\r");
  221.             printf("[ESC to abort]");
  222.             pos_cursor(32, 5+OPTIONS);
  223.             leng = get_str(search_str);
  224.             Bioskeys(); 
  225.             if (leng <= 0) break;
  226.             found = -1;
  227.             pos_cursor(0, 8+OPTIONS);
  228.             printf(" #  name\n\r");
  229.             printf("--- ----");
  230.             do {
  231.                 found = search(search_str, found+1);
  232.                 if (found < cur_voice) {
  233.                     pos_cursor(0, 10+OPTIONS);
  234.                     scr_func(CLEAR_TO_EOL);
  235.                     printf("%03d '%s'", found, 
  236.                         v_names[found]);
  237.                     pos_cursor(0, 6+OPTIONS);
  238.                     scr_func(CLEAR_TO_EOL);
  239.                     printf("Continue search (y/n)? \007");
  240.                     printf("%c", (ans = Crawcin()));
  241.                 }
  242.                 else {
  243.                     pos_cursor(0, 10+OPTIONS);
  244.                     scr_func(CLEAR_TO_EOL);
  245.                     printf("*** NONE");
  246.                     pos_cursor(0, 6+OPTIONS);
  247.                     scr_func(CLEAR_TO_EOL);
  248.                     printf("-- Hit any key to continue --");
  249.                     wait();
  250.                 }
  251.             } while (found<cur_voice && (ans == 'y' || ans == 'Y'));
  252.             break;
  253.         case 'q':
  254.         case 'Q':
  255.             printf("q");
  256.             break;
  257.         default:
  258.             printf("\007");
  259.             printf("\n\rBad option '%c' - re-try", key);
  260.             break;
  261.         }
  262.     } while (key != 'q' && key != 'Q');
  263.     if (init_rez == 0) Setscreen(-1L, -1L, 0);
  264.     curses_cleanup();
  265. }
  266.  
  267. /* get_voices: read the standard voice library file and initialize the
  268.     voices in memory */
  269. get_voices(names, voice_data)
  270. char names[][80], voice_data[][TOTAL_SIZE];
  271. {
  272.     long    result;
  273.     int    handle;
  274.  
  275.     check_disk();
  276.     if (cur_space < 80 + TOTAL_SIZE) {
  277.         warn(
  278.     "WARNING: There is not enough space on the disk to store more voices");
  279.     }
  280.     result = Fsfirst(VOICE_FILE, 0);
  281.     if (result == EFILNF) {
  282.         printf("file '%s' not found -- attempting to create\n\r",
  283.             VOICE_FILE);
  284.         handle = Fcreate(VOICE_FILE, 0);
  285.         if (handle < 0) {
  286.             sprintf(out, "cannot create '%s'", VOICE_FILE);
  287.             error(out);
  288.         }
  289.         else {
  290.             printf("'%s' created\n\r", VOICE_FILE);
  291.             Fclose(handle);
  292.             result = E_OK;
  293.         }
  294.     }
  295.     if (result == E_OK) {
  296.         handle = Fopen(VOICE_FILE, READ);
  297.         if (handle < 0) {
  298.             sprintf(out, "cannot open '%s'", VOICE_FILE);
  299.             error(out);
  300.         }
  301.         else {
  302.             printf("file opened\n\r");
  303.         }
  304.     }
  305.     else {
  306.         sprintf(out, "cannot find '%s'", VOICE_FILE);
  307.         error(out);
  308.     }
  309.     cur_voice = 0;
  310.     printf("reading in voice data\n\r");
  311.     while(TRUE) {
  312.         if (scan_name(handle, names[cur_voice]) != OK) break;
  313.         if (strlen(names[cur_voice]) > 0) {
  314.             if (scan_voice(handle, voice_data[cur_voice]) != OK) 
  315.                 break;
  316.